import pygame.image


class Bomb(object):
    def __init__(self):
        # 加载爆炸资源
        self.image = [pygame.image.load("plane/img/enemy1_down" + str(v) + ".png") for v in range(1, 4)]
        # 设置当前爆炸播放索引
        self.index = 0
        # 播放间隔时间
        self.interval = 10
        self.interval_index = 0
        # 爆炸位置
        self.position = [0, 0]
        # 是否可见
        self.visible = False

    # 设置播放位置
    def set_position(self, x, y):
        self.position[0] = x
        self.position[1] = y

    # 播放爆炸
    def acction(self):
        if not self.visible:
            return
        self.interval_index += 1
        if self.interval_index < self.interval:
            return
        self.interval_index = 0
        self.index += 1
        if self.index >= len(self.image):
            self.index = 0
            self.visible = False

    # 绘制爆炸
    def draw(self, screen):
        if not self.visible:
            return
        screen.blit(self.image[self.index], (self.position[0], self.position[1]))